<?php

/**
 * This is the model class for table "res_assignment".
 *
 * The followings are the available columns in table 'res_assignment':
 * @property string $id
 * @property string $course_id
 * @property string $resource_id
 * @property string $dead_line
 * @property integer $is_published
 * @property integer $teacher_id
 * @property string $publish_time
 * @property string $requirement
 *
 * The followings are the available model relations:
 * @property CourseBasicInfo $course
 * @property ResResource $resource
 * @property ResHomework[] $resHomeworks
 */
class ResAssignment extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return ResAssignment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'res_assignment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('course_id, resource_id, dead_line, teacher_id, publish_time, requirement', 'required'),
			array('is_published, teacher_id', 'numerical', 'integerOnly'=>true),
			array('course_id, resource_id', 'length', 'max'=>11),
			array('requirement', 'length', 'max'=>2048),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, course_id, resource_id, dead_line, is_published, teacher_id, publish_time, requirement', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'course' => array(self::BELONGS_TO, 'CourseBasicInfo', 'course_id'),
			'resource' => array(self::BELONGS_TO, 'ResResource', 'resource_id'),
			'resHomeworks' => array(self::HAS_MANY, 'ResHomework', 'assignment_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'course_id' => 'Course',
			'resource_id' => 'Resource',
			'dead_line' => 'Dead Line',
			'is_published' => 'Is Published',
			'teacher_id' => 'Teacher',
			'publish_time' => 'Publish Time',
			'requirement' => 'Requirement',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('course_id',$this->course_id,true);
		$criteria->compare('resource_id',$this->resource_id,true);
		$criteria->compare('dead_line',$this->dead_line,true);
		$criteria->compare('is_published',$this->is_published);
		$criteria->compare('teacher_id',$this->teacher_id);
		$criteria->compare('publish_time',$this->publish_time,true);
		$criteria->compare('requirement',$this->requirement,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}